package logic

import (
	"context"
	"gorm.io/gorm"
	"shopping-cart/models/mysql"

	"shopping-cart/shoprpc/internal/svc"
	"shopping-cart/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CarListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCarListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CarListLogic {
	return &CarListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CarListLogic) CarList(in *shoprpc.CarListRequest) (*shoprpc.CarListResponse, error) {
	// todo: add your logic here and delete this line
	car := mysql.Car{
		Model: gorm.Model{ID: uint(in.CarId)},
	}
	mysql.DB.Debug().Find(&car)

	return &shoprpc.CarListResponse{
		UserId:  int64(car.UserId),
		ShopId:  int64(car.ShopId),
		KuCunId: int64(car.KuCunId),
		KuNum:   int64(car.KuNum),
	}, nil
}
